package com.github.skystardust.lotteryex.lottery.item;

import com.github.skystardust.lotteryex.lottery.item.api.Award;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

@EqualsAndHashCode(of = "uuid")
@ToString
public abstract class AwardItem<T> implements Award<T> {
    private String type;
    private UUID uuid;
    private T awardItem;

    public AwardItem(T awardItem) {
        this(UUID.randomUUID(), awardItem);
    }

    public AwardItem(UUID uuid, T awardItem) {
        this.uuid = uuid;
        this.awardItem = awardItem;
        this.type = getClass().getSimpleName();
    }

    public AwardItem(Map<String, Object> stringObjectMap) {
        this.type = getClass().getSimpleName();
        this.uuid = UUID.fromString(((String) stringObjectMap.get("uuid")));
    }

    public T getAwardItem() {
        return awardItem;
    }

    public void setAwardItem(T awardItem) {
        this.awardItem = awardItem;
    }

    public UUID getUuid() {
        return uuid;
    }

    public void setUuid(UUID uuid) {
        this.uuid = uuid;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public Map<String, Object> serialize() {
        TreeMap<String, Object> objectObjectTreeMap = new TreeMap<>();
        objectObjectTreeMap.put("uuid", uuid.toString());
        objectObjectTreeMap.put("awardItem", awardItem);
        return objectObjectTreeMap;
    }

}
